Skip to main content

All Questions

1vote
6answers
496views

How encapsulating what varies can help us?

I have a question about encapsulation and I read these two topic (this & this) but I got more confused. I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to ...
Mehdi's user avatar
3votes
5answers
371views

Add specific behavior inside classes

I'm learning to make games with OOP and there's something I don't understand. What I can see is that the more I add methods to a class, the less it becomes reusable and flexible. For example, if we ...
Voko's user avatar
  • 233
0votes
1answer
105views

Could a getState() method in a Caretaker violates Memento Pattern?

I have looked at several examples for implementations of Momento on the web. I wonder if it is correct to retrieve the status of Originator, since this is much more accurate, up-to-date and reliable? ...
celsowm's user avatar
13votes
1answer
4kviews

Using friend classes to encapsulate private member functions in C++ - good practice or abuse?

So I noticed it's possible to avoid putting private functions in headers by doing something like this: // In file pred_list.h: class PredicateList { int somePrivateField; ...
Robert Fraser's user avatar
1vote
3answers
892views

Is the Liskov Substitution Principle concerned with protecting state invariants?

Wiki says: Substitutability is a principle in object-oriented programming stating that, in a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S (...
user1787812's user avatar
27votes
4answers
16kviews

What does it mean when one says “Encapsulate what varies”?

One of the OOP principles I came across is: -Encapsulate what varies. I understand what the literal meaning of the phrase is i.e. hide what varies. However, I don't know how exactly would it ...
Haris Ghauri's user avatar
65votes
10answers
36kviews

Do you generally send objects or their member variables into functions?

Which is generally accepted practice between these two cases: function insertIntoDatabase(Account account, Otherthing thing) { database.insertMethod(account.getId(), thing.getId(), thing....
AJJ's user avatar
  • 3,028
15votes
3answers
23kviews

Best practices for using public, protected, private?

Is it fair to say that it is good practice to default everything to private up front when coding something? And then only upgrade it to protected if a subclass needs it, or public if another class ...
AJJ's user avatar
  • 3,028
0votes
1answer
238views

How much to encapsulate when objects being dealt with are pretty similar

As I have been answering questions related to object-oriented design and how to go about reducing the amount of classes to make sure that there is not a lot of "class clutter" and code repetition I ...
SurrealSyntax's user avatar
2votes
1answer
615views

What's the right OO way to create a counter/inventory class that works for both differentiated and undifferentiated countables?

You are writing a videogame about trading beans. Red beans, black beans, pinto beans, you name it. As everybody knows all beans are the same. You write the "Inventory" class for a trader in that ...
CarrKnight's user avatar

close